package org.xqp.hrm.web.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xqp.hrm.doc.CourseDoc;
import org.xqp.hrm.dto.CourseSearchDto;
import org.xqp.hrm.service.ICourseESService;
import org.xqp.hrm.util.AjaxResult;

//课程相关
@RestController
@RequestMapping("/course")
public class CourseESController {

    @Autowired
    private ICourseESService courseESService;

    //搜索课程
    @PostMapping("/search")
    public AjaxResult search(@RequestBody CourseSearchDto dto){
        return AjaxResult.me().setResultObj(courseESService.search(dto));
    }

    //保存课程
    @RequestMapping("/save")
    @PreAuthorize("hasAuthority('course:save')") // 要有course:save權限才能訪問
    public AjaxResult save(@RequestBody CourseDoc doc){
        courseESService.save(doc);
        return AjaxResult.me();
    }

}
